package org.sunrise.game.rpc.service;

import org.sunrise.game.common.db.DbService;
import org.sunrise.game.common.log.LogCore;

import java.util.HashMap;
import java.util.Map;

public class ServiceManager {
    public static final DbService dbService = new DbService();
    private static final Map<String, BaseService> services = new HashMap<>();

    public static void registerService(BaseService instance) {
        services.put(instance.getClass().getSimpleName(), instance);
    }

    public static BaseService getService(String className) {
        return services.get(className);
    }

    public static void initAll() {
        long startTime = System.currentTimeMillis();
        for (BaseService service : services.values()) {
            service.init();
        }
        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        LogCore.RpcUtils.debug("All Service init end, took {} ms", duration);
    }
}

